@extends('layouts.master')
@section('title')
    列表
@endsection
@push('stylesheets')
    <link href="{{ URL::asset('/static/web/css/plugins/sweetalert/sweetalert.css')}}?v=33" rel="stylesheet">
@endpush
@section('content')
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form class="layui-form" action="">
                        <div class="layui-inline">
                            <label class="layui-form-label">骑手姓名:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="query[realname]" lay-verify="" placeholder="姓名搜索"
                                       value="{{$query['realname']}}" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">手机号:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="query[phone]" lay-verify="" placeholder="手机号搜索"
                                       value="{{$query['phone']}}" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">接单日期:</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" class="layui-input  start_time" value="{{$query['start_time']}}"
                                       name="query[start_time]"
                                       readonly>
                            </div>
                            -
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" class="layui-input end_time" value="{{$query['end_time']}}"
                                       name="query[end_time]"
                                       readonly>
                            </div>
                        </div>
                        <div class="layui-inline" style="padding-bottom: 5px">
                            <div class="layui-input-inline">
                                <input type="hidden" name="page_num" value="{{$currentPageNum}}">
                                <button name="submit" class="btn btn-success" type="submit">搜索</button>
                            </div>
                        </div>
                    </form>
                    @include('common.toolbar', ['pager' => $list])
                    <form class="layui-form form-horizontal" id="ajaxform">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>真实姓名</th>
                                <th>总单数</th>
                                <th>当月订单</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($list as $index => $item)
                                <tr>
                                    <th>{{$item->id}}</th>
                                    <th>id:{{$item->user->id}}<br/>{{$item->realname}}<br/>{{$item->phone}}</th>
                                    <td>
                                        {{$item->counts}}
                                    </td>
                                    <th>
                                        {{$item->order_count}}
                                    </th>

                                    <th>
                                        {{$item->status_text}}
                                    </th>
                                    <th>
                                        <a href="{{route('escort.show_chart',['escort_id'=>$item->id])}}"
                                           class="btn btn-success"><i class="fa fa-file-text-o"></i> 查看详情</a>
                                    </th>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </form>
                    @include('common.pagination', ['pager' => $list])
                </div>
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script>
        layui.use(['laydate', 'element'], function () {
            var laydate = layui.laydate, element = layui.element;
            //日期时间选择器
            laydate.render({
                elem: '.start_time'
                , type: 'datetime'
            });
            laydate.render({
                elem: '.end_time'
                , type: 'datetime'
            });
        });
    </script>
@endsection
@section('script')
    <script>
        layui.use(['laydate', 'element','form'], function () {
            var form = layui.form;

        });
        function show_license(index){
            var viewer = new Viewer(document.getElementById('license'+index),{
                hidden: function () {
                    viewer.destroy();
                },
            });
            viewer.show()
        }

        function setSchool(school_ids, escort_id) {
            $.ajax({
                url: '{{route('escort.set_escort_schools')}}',
                type: 'POST',
                data: {school_ids, escort_id},
                dataType: "json",
                success: function (result) {
                    console.log(result);
                    return
                    layer.msg(result.message, {time: 2000, icon: 1});
                    var index = parent.layer.getFrameIndex(window.name);
                    setTimeout(function () {
                        parent.layer.close(index);
                        window.parent.location.reload();
                    }, 1000);
                }
            });
        }

        function setLeader(uid, escort_id) {
            $.ajax({
                url: '{{route('escort.set_leader')}}',
                type: 'POST',
                data: {uid, escort_id},
                dataType: "json",
                success: function (result) {
                    layer.msg(result.message, {time: 2000, icon: 1});
                    var index = parent.layer.getFrameIndex(window.name);
                    setTimeout(function () {
                        parent.layer.close(index);
                        window.parent.location.reload();
                    }, 1000);
                }
            });
        }

        function reject(e) {
            var id = $(e).data('id')
            require(["{{ URL::asset('/static/web/js/plugins/sweetalert/sweetalert.min.js')}}"], function (swal) {
                layui.use(['laydate', 'element'], function () {
                    swal({
                        title: '驳回',
                        input: 'textarea',
                        confirmButtonText: "提交",
                        cancelButtonText: "取消",
                        showCancelButton: true
                    }).then(function (result) {

                        var reason = result.value;
                        if (reason && result.dismiss != 'cancel') {
                            var index = layer.load(0);
                            $.ajax({
                                url: '{{route('escort.change')}}',
                                type: 'GET',
                                data: {id, reason, status:-1},
                                dataType: "json",
                                success: function (result) {
                                    layer.close(index);
                                    if (result.errno || result.errno == 0) {
                                        layer.msg(result.message, {time: 2000, icon: 6});
                                        window.location.reload();
                                    } else {
                                        layer.msg(result.message, {time: 2000, icon: 5});
                                    }
                                }
                            });
                        }
                    })
                });
            });
        }
    </script>
@endsection
